# 用户权限
user_permission = 11  # 0b1011
# 权限因子
DEL_PERMISSION = 8  # 0b1000
READ_PERMISSION = 4  # 0b0100
WRITE_PERMISSION = 2  # 0b0010
EXE_PERMISSION = 1  # 0b0001


# 用户权限 & 权限因子 != 0b0000(即0) ==> 有该种权限

def check_permission(user_permission, required_permission):
    def handle_action(fn):
        def do_action():
            if user_permission & required_permission:
                fn()
            else:
                print('warning: you don\'t have required permission')

        return do_action

    return handle_action


@check_permission(user_permission, DEL_PERMISSION)
def delete():
    print('deleting')


@check_permission(user_permission, READ_PERMISSION)
def read():
    print('reading')


@check_permission(user_permission, WRITE_PERMISSION)
def write():
    print('writing')


@check_permission(user_permission, EXE_PERMISSION)
def execute():
    print('executing')


read()
write()
execute()
delete()
